package com.al.ofc.dao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.naming.NamingException;

import util.DBUtil;

public class OFCDao {
	
	public Map<String,Double> query(String sql){
		Map<String,Double> map = new LinkedHashMap<String, Double>();
		Connection conn = null;
		Statement stat = null;
		ResultSet rs = null;
		try {
			conn = DBUtil.getConnection();
			stat = DBUtil.getStatement(conn);
			rs = stat.executeQuery(sql);
			while(rs.next()){
				String x = rs.getString(2);
				String y = rs.getString(1);
				map.put(x, Double.valueOf(y));
			}
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			DBUtil.close(conn, stat, rs);
		}
		return map;
	}
}
